#include "stdafx.h"
#include "R09RegisterSet.h"


R09RegisterSet::R09RegisterSet(void)
{
	registers = gcnew array<UInt32>(REGISTER_COUNT);

	registers[14] = 0;
	registers[15] = 1;
}

UInt32 R09RegisterSet::GetValueAt(UInt32 i)
{
	if (i >= 0 && i < REGISTER_COUNT)
	{
		return registers[i];
	}
	
	throw gcnew IndexOutOfRangeException(
		"Memory access out of range. Memory start address: 0" +
		" - Memory end address: " + 
		(REGISTER_COUNT - 1) + " - Access Adress: " + i);
}

void R09RegisterSet::SetValueAt(UInt32 i, UInt32 value)
{
	if (i >= 0 && i < REGISTER_COUNT)
	{
		if (!(i == 14 || i == 15))
		{
			registers[i] = value;

			return;
		}
		else
		{
			throw gcnew ArgumentException("Registers 14 (Zero) and 15 (One) cannot be written to!", "Register Number");
		}
	}

	throw gcnew IndexOutOfRangeException(
		"Memory access out of range. Memory start address: 0" + 
		" - Memory end address: " + 
		(REGISTER_COUNT - 1) + " - Access Adress: " + i);
}
